<?php
/**
 * Jishupu-Laravel-Vue-Admin
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/22
 */

namespace App\Http\Controllers;

use App\Services\AttachmentService;
use Illuminate\Http\Request;

/**
 * 附件模块
 *
 * Class AttachmentController
 * @package App\Http\Controllers
 */
class AttachmentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    /**
     * 综合上传
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function upload()
    {
        $attachmentService = new AttachmentService();
        $result = $attachmentService->upload();
        return $this->successUploaded(['items' => $result]);
    }

    /**
     * 上传图片
     * @return \Illuminate\Http\JsonResponse
     */
    public function uploadImage()
    {
        $attachmentService = new AttachmentService();
        $result = $attachmentService->uploadImage();
        return $this->successUploaded(['items' => $result]);
    }

    /**
     * 上传音视频
     * @return \Illuminate\Http\JsonResponse
     */
    public function uploadMedia()
    {
        $attachmentService = new AttachmentService();
        $result = $attachmentService->uploadMedia();
        return $this->successUploaded(['items' => $result]);
    }

    /**
     * 多文件上传
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function multipleUpload()
    {
        $attachmentService = new AttachmentService();
        $result = $attachmentService->multipleUpload();
        return $this->successUploaded(['items' => $result]);
    }

    /**
     * 根据附件ID集获取附件列表
     * 场景：提供其他模块调用图片等附件回显
     * @param $id // 例：1 或 1,2
     * @return \Illuminate\Http\JsonResponse
     */
    public function list($id)
    {
        return $this->success('', ['items' => AttachmentService::previewList($id)]);
    }

    /**
     * 附件配置
     * @return \Illuminate\Http\JsonResponse
     */
    public function config()
    {
        $attachmentService = new AttachmentService();
        return $this->success('', $attachmentService->config());
    }


}
